home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_kdelibs.idb / usr / freeware / kde / include / kbuttonbox.h.z / kbuttonbox.h
Encoding:
C/C++ Source or Header  |  1999-01-26  |  3.5 KB  |  116 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1997 Mario Weilguni (mweilguni@sime.com)
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public License
  15.     along with this library; see the file COPYING.LIB.  If not, write to
  16.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17.     Boston, MA 02111-1307, USA.
  18. */
  19. /* 
  20.  * KButtonBox class
  21.  *
  22.  * A container widget for buttons. Uses Qt layout control to place the
  23.  * buttons, can handle both vertical and horizontal button placement.
  24.  * The default border is now 0 (easier to deal with layouts). The space
  25.  * between buttons is now more Motif compliant
  26.  */
  27.  
  28. #ifndef __KBUTTONBOX__H__
  29. #define __KBUTTONBOX__H__
  30.  
  31. #include <qwidget.h>
  32. #include <qpushbt.h>
  33. #include <qlist.h>
  34.  
  35. /**
  36.   * This class is used internally.
  37.   */
  38. class KButtonBoxItem {
  39. public:
  40.   QPushButton *button;
  41.   bool noexpand;
  42.   int stretch;
  43.   int actual_size;
  44. };
  45.  
  46.  
  47. class KButtonBox : public QWidget {
  48.   Q_OBJECT
  49. public:
  50.   enum { VERTICAL = 1, HORIZONTAL = 2 };
  51.  
  52.   /**
  53.     * Creates an empty container for buttons. If _orientation is 
  54.     * KButtonBox::VERTICAL, the buttons inserted with @see addButton
  55.     * are layouted from top to bottom, otherwise they are layouted 
  56.     * from left to right.
  57.     */
  58.   KButtonBox(QWidget *parent, int _orientation = HORIZONTAL, 
  59.          int border = 0, int _autoborder = 6);
  60.  
  61.   /**
  62.     * The destructor is needed, otherwise gcc 2.7.2.1 may report an 
  63.     * internal compiler error. It does nothing.
  64.     */
  65.   ~KButtonBox();
  66.  
  67.   /**
  68.     * @return the minimum size needed to fit all buttons. This size is
  69.     * calculated by the with/height of all buttons plus border/autoborder
  70.     */
  71.   virtual QSize sizeHint() const;
  72.  
  73.   virtual void resizeEvent(QResizeEvent *);
  74.  
  75.   /**
  76.     * adds a new @see QPushButton and @return a pointer to the newly 
  77.     * created button. If noexpand is FALSE, the width of the button is
  78.     * adjusted to fit the other buttons (the maximum of all buttons is
  79.     * taken). If noexpand is TRUE, the width of this button will be
  80.     * set to the minimum width needed for the given text).
  81.     */
  82.   QPushButton *addButton(const char *text, bool noexpand = FALSE);
  83.  
  84.   /**
  85.     * This adds a stretch to the buttonbox. @see QBoxLayout for details.
  86.     * Can be used to separate buttons (i.e. if you add the buttons "Ok",
  87.     * "Cancel", add a stretch and then add the button "Help", "Ok" and
  88.     * "Cancel" will be left-aligned (or top-aligned for vertical) while
  89.     * "Help" will be right-aligned (or bottom-aligned for vertical).
  90.     */
  91.   void addStretch(int scale = 1);
  92.  
  93.   /**
  94.     * This function must be called ONCE after all buttons have been
  95.     * inserted. It will start layout control.
  96.     */
  97.   void layout();
  98.  
  99. protected:
  100.   /**
  101.     * @return the best size for a button. Checks all buttons and takes
  102.     * the maximum width/height.
  103.     */
  104.   QSize bestButtonSize() const;
  105.   void  placeButtons();
  106.   QSize buttonSizeHint(QPushButton *) const;
  107.  
  108. protected:
  109.   int _border, _autoborder;
  110.   int orientation;
  111.   bool activated;
  112.   QList<KButtonBoxItem> buttons;
  113. };
  114.  
  115. #endif
  116.